package com.tt.vtg.plain.info;

import java.util.List;
import java.util.stream.Collectors;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.tt.vtg.dao.entity.User;

public class UserInfo {
	private String userId;
	private String name;
	
	@JsonIgnore
	private List<String> roleIds;
	@JsonIgnore
	private List<String> permissionIds;
	
	public UserInfo(){}
	public UserInfo(User user){
		if(user != null){
			userId = user.getUserId();
			name = user.getUserName();
			roleIds = user.getRoles().stream().map(r->r.getRoleId()).collect(Collectors.toList());
			permissionIds = user.getRoles().stream().flatMap(r->r.getPermissions().stream())
									.map(p->p.getPermissionId()).collect(Collectors.toList());
		}
	}
	
	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	public List<String> getRoleIds() {
		return roleIds;
	}
	public void setRoleIds(List<String> roleIds) {
		this.roleIds = roleIds;
	}
	public List<String> getPermissionIds() {
		return permissionIds;
	}
	public void setPermissionIds(List<String> permissionIds) {
		this.permissionIds = permissionIds;
	}
	@Override
	public String toString() {
		return "UserInfo [userId=" + userId + ", name=" + name + ", roleIds="
				+ roleIds + ", permissionIds=" + permissionIds + "]";
	}
}
